package csdn_2;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test2 {
    public static void main(String[] args) {
        String srcFilePath="D:\\javacode\\javacode\\IO_1\\happy.txt";//源路径
        String destFilePath="D:\\javacode\\javacode\\IO_1\\happy2.txt";//拷贝路径
        FileReader fileReader=null;
        FileWriter fileWriter=null;

        try {
            fileReader=new FileReader(srcFilePath);//创建字符输入流对象
            fileWriter=new FileWriter(destFilePath);//创建字符输出流对象

            char []buf=new char[8];
            int readLen=0;
            while((readLen=fileReader.read(buf))!=-1){
                fileWriter.write(buf,0,readLen);
            }
            System.out.println("拷贝完成~");


        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                if(fileWriter!=null) {
                    fileWriter.close();
                }
                if(fileReader!=null){
                    fileReader.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
